<div class="layui-card">
    <div class="layui-card-header">
        <h2 class="header-title">类容管理</h2>
        <span class="layui-breadcrumb pull-right">
          <a href="#!console">首页</a>
          <a><cite>类容管理</cite></a>
        </span>
    </div>
    <div class="layui-card-body">
        <!-- 搜索条件 -->
        <div class="layui-form toolbar">
            <form id="searchForm" onsubmit="return false;">
                标题：<input name="title" class="layui-input search-input" type="text" placeholder="输入标题名"/>&emsp;

                <button id="content-btn-search" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索
                </button>
            </form>
        </div>
        <!-- 表格顶部操作列 -->
        <script type="text/html" id="content-toolbar">
            <div class="layui-btn-container">

                <button class="layui-btn layui-btn-normal layui-btn-sm" lay-event="add"><i
                        class="layui-icon"></i>添加
                </button>

            </div>
        </script>
        <table class="layui-table" id="content-table" lay-filter="content-table"></table>
    </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="content-table-bar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="view">查询</a>
</script>

<script>
    layui.use(['form', 'table', 'config', 'crown'], function () {
        var $ = layui.jquery;
        var table = layui.table;
        var config = layui.config;
        var layer = layui.layer;
        var crown = layui.crown;

        // 渲染表格
        var contentTable;

        var renderTable= function(){
            contentTable = table.render({
                elem: '#content-table',
                toolbar: '#content-toolbar',
                url: config.serverUrl + '/content',
                request: config.request,
                parseData: config.parseData,
                response: config.response,
                headers: {Authorization: config.getToken()},
                page: true,
                cols: [[
                    {field: 'id', title: 'ID'},
                    {field: 'title', align: 'center', sort: true, title: '标题'},
                    {field: 'tag', align: 'center', sort: true, title: '标签'},
                    {field: 'createTime', align: 'center', sort: true, title: '创建时间'},
                    {field: 'updateTime', align: 'center', sort: true, title: '修改时间'},
                    {fixed: 'right', align: 'center', toolbar: '#content-table-bar', title: '操作'}
                ]]
            });
        };

        renderTable();

        // 工具条点击事件
        table.on('tool(content-table)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            if (layEvent === 'view') {

                crown.get('/content/' + data.id, {async: false}, function (data) {
                    crown.putTempData('t_content', data.result);
                });

                //示范一个公告层
                layer.open({
                    type: 1
                    ,title: false //不显示标题栏
                    ,closeBtn: true
                    ,area: '500px;'
                    ,shade: 0.8
                    ,id: 'LAY_layuipro' //设定一个id，防止重复弹出
                    ,btn: ['关闭']
                    ,btnAlign: 'c'
                    ,moveType: 1 //拖拽模式，0或者1
                    ,success: function(layero){

                        $('#LAY_layuipro').load("components/views/content/view.html", function () {

                        });
                    }
                });

            }
        });

        // 表格顶部操作列
        table.on('toolbar(content-table)', function (obj) {
            if (obj.event === 'add') {
                showEditModel()
            }
        });

        var showEditModel = function () {

            crown.popupCenter({
                title: '添加类容',
                path: 'components/views/content/form.html',
                area: '1000px',
                finish: function () {
                    renderTable();
                }
            });
        };

        // 搜索按钮点击事件
        $('#content-btn-search').click(function () {
//            contentTable.reload({where: crown.getSearchForm()});

            $.ajax({
                url: "http://10.145.205.45:9080/adjustment/mobileHelper/queryPreAuditAffairList.go",
                type: "POST",   //post请求方式
                data:{"login":"PANYL"},
                dataType: "json",
                success: function (data) {

                    console.log("success");
                    var result = JSON.stringify(data);
                    console.log(result)
                }

            });

        });




    });
</script>